package com.ruoyi.project.system.zbj.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.zbj.domain.Zbj;
import com.ruoyi.project.system.zbj.service.IZbjService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * zbjController
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@Controller
@RequestMapping("/system/zbj")
public class ZbjController extends BaseController
{
    private String prefix = "system/zbj";

    @Autowired
    private IZbjService zbjService;

    @RequiresPermissions("system:zbj:view")
    @GetMapping()
    public String zbj()
    {
        return prefix + "/zbj";
    }

    /**
     * 查询zbj列表
     */
    @RequiresPermissions("system:zbj:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Zbj zbj)
    {
        startPage();
        zbj.setUserId(getUserId());
        List<Zbj> list = zbjService.selectZbjList(zbj.getUserId());
        return getDataTable(list);
    }

    /**
     * 导出zbj列表
     */
    @RequiresPermissions("system:zbj:export")
    @Log(title = "zbj", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Zbj zbj)
    {
        zbj.setUserId(getUserId());
        List<Zbj> list = zbjService.selectZbjList(zbj.getUserId());
        ExcelUtil<Zbj> util = new ExcelUtil<Zbj>(Zbj.class);
        return util.exportExcel(list, "zbj数据");
    }

    /**
     * 新增zbj
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存zbj
     */
    @RequiresPermissions("system:zbj:add")
    @Log(title = "zbj", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Zbj zbj)
    {
        return toAjax(zbjService.insertZbj(zbj));
    }

    /**
     * 修改zbj
     */
    @RequiresPermissions("system:zbj:edit")
    @GetMapping("/edit/{zbjId}")
    public String edit(@PathVariable("zbjId") Long zbjId, ModelMap mmap)
    {
        Zbj zbj = zbjService.selectZbjByZbjId(zbjId);
        mmap.put("zbj", zbj);
        return prefix + "/edit";
    }

    /**
     * 修改保存zbj
     */
    @RequiresPermissions("system:zbj:edit")
    @Log(title = "zbj", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Zbj zbj)
    {
        return toAjax(zbjService.updateZbj(zbj));
    }

    /**
     * 删除zbj
     */
    @RequiresPermissions("system:zbj:remove")
    @Log(title = "zbj", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zbjService.deleteZbjByZbjIds(ids));
    }
}
